//
//  PayModel.m
//  MJApp
//
//  Created by 王亮 on 15/8/25.
//  Copyright (c) 2015年 王亮. All rights reserved.
//

#import "PayModel.h"

@implementation PayModel

+ (void)payWithPayState:(PayState)payState {
    
    if (payState == PayStateAli) {
        
        [self payForAli];
        
    }else if(payState == PayStateWeixin) {
        
        [self payForWeixin];
    }
}


+ (void)payForAli {
    
    PayProduct *payProduct = [[PayProduct alloc] init];
    payProduct.price = @"0.01";
    payProduct.desc = @"test ming jing";
    payProduct.orderID = @"13225435353JH";
    payProduct.name = @"test ming jing";
    
    [WLPayModel payModelProudct:payProduct withBlock:^(NSDictionary *resultDictionary) {
        
        NSString * str = [NSString stringWithFormat:@"%@",resultDictionary[@"resultStatus"]];
        if ([str isEqualToString:@"9000"]) {
            //支付成功
//            [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"支付成功"];
            
        }else if ([str isEqualToString:@"8000"]) {
            //正在处理中
//            [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"正在处理中"];
        }else if ([str isEqualToString:@"6001"]) {
            //用户中途取消
//            [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"用户中途取消"];
        }else if ([str isEqualToString:@"6002"]) {
            //网络连接出错
//            [[DMCAlertCenter defaultCenter] postAlertWithMessage:@"网络连接出错"];
        }
        
    }];
}

+ (void)payForWeixin {
    
    NSMutableDictionary *orderDic = [NSMutableDictionary dictionary];
    orderDic[@"order_name"] = @"test ming jing";
    orderDic[@"order_price"] = @"1"; //分为单位
    orderDic[@"orderno"] = @"13225435353JH";
    
    payRequsestHandler *pay = [[payRequsestHandler alloc] init];
    [pay init:APP_ID mch_id:MCH_ID];
    [pay setKey:@"1040161xiaopoiuytrewqmnbvcxzasdf"];
    NSDictionary *dic = [pay sendPay_demo:orderDic];
    PayReq* req             = [[PayReq alloc] init];
    req.openID              = [dic objectForKey:@"appid"];
    req.partnerId           = [dic objectForKey:@"partnerid"];
    req.prepayId            = [dic objectForKey:@"prepayid"];
    req.nonceStr            = [dic objectForKey:@"noncestr"];
    NSMutableString *stamp  = [dic objectForKey:@"timestamp"];
    req.timeStamp           = stamp.intValue;
    req.package             = [dic objectForKey:@"package"];
    req.sign                = [dic objectForKey:@"sign"];
    [WXApi sendReq:req];
}

@end
